package com.lx.video.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lx.bilibili.entity.VideoAndVideoPlayHistory;
import com.lx.bilibili.entity.VideoPlayHistory;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lx
 * @since 2025-04-06
 */
public interface VideoAndVideoplayhistroyMapper extends BaseMapper<VideoAndVideoPlayHistory> {


    @Select("SELECT\n" +
            "	b.id,\n" +
            "	c.id vphid,\n" +
            "	c.endtime,\n" +
            "	c.TIME,\n" +
            "	b.image,\n" +
            "	b.vname,\n" +
            "	a.NAME\n," +
            "	c.uid\n," +
            "	b.videoLength\n" +
            "FROM\n" +
            "	`user` a,\n" +
            "	video b,\n" +
            "	videoplayhistroy c \n" +
            "WHERE\n" +
            "	a.id = b.uid \n" +
            "	AND b.id = c.vid \n" +
            "	AND c.uid = #{id} ")

    List<VideoAndVideoPlayHistory> getVideoPlayHistory(int id);


    @Select("SELECT\n" +
            "	b.id,\n" +
            "	c.id vphid,\n" +
            "	c.endtime,\n" +
            "	c.TIME,\n" +
            "	b.image,\n" +
            "	b.vname,\n" +
            "	a.NAME,\n" +
            "	c.uid,\n" +
            "	b.videoLength\n" +
            "FROM\n" +
            "	`user` a,\n" +
            "	video b,\n" +
            "	videoplayhistroy c \n" +
            "WHERE\n" +
            "	a.id = b.uid \n" +
            "	AND b.id = c.vid \n" +
            "	AND c.uid = #{id}\n" +
            "	and c.time between #{startTime} and #{endTime}")

    List<VideoAndVideoPlayHistory> getVideoPlayHistoryToday(int id, LocalDateTime startTime, LocalDateTime endTime);


    @Select("SELECT\n" +
            "	* \n" +
            "FROM\n" +
            "	videoplayhistroy a,\n" +
            "	video b,\n" +
            "	`user` c \n" +
            "WHERE\n" +
            "	a.vid = b.id \n" +
            "	AND b.uid = c.id \n" +
            "	AND a.uid = #{id} \n" +
            "	AND (\n" +
            "	c.NAME LIKE #{text} \n" +
            "	OR b.vname LIKE #{text})")


    List<VideoAndVideoPlayHistory> getVideoPlayHistoryByText(String text, int id);
}
